package com.nuoniu.sibanyun.controller.production;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpTeam;
import com.nuoniu.sibanyun.service.erp.IErpAccountService;
import com.nuoniu.sibanyun.service.erp.IErpTeamService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 班组 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-30
 */
@RestController
@RequestMapping("/erp/team")
@Api(value = "班组管理", tags = "班组管理")
public class ErpTeamController extends BaseController {

    @Autowired
    private IErpTeamService teamService;

    /**
     * 保存班组
     * @author 小啊刚
     * @date 2020-12-30
     */
    @PostMapping("save")
    @ApiOperation("保存班组")
    public HttpResult save(@RequestBody ErpTeam erpTeam) {
        if(StringUtils.isBlank(erpTeam.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }
        if(StringUtils.isBlank(erpTeam.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        teamService.saveErpTeam(erpTeam);
        return HttpResult.ok();
    }

    @GetMapping("pageList")
    @ApiOperation("获取列表")
    public HttpResult<ErpTeam> pageList(Page page, ErpTeam erpTeam) {
        return HttpResult.ok(teamService.pageList(page, erpTeam));
    }

    @DeleteMapping("delete")
    @ApiOperation("删除班组")
    public  HttpResult delete(Long id) {
        teamService.removeById(id);
        return HttpResult.ok();
    }
}
